package com.ruoyi.web.controller.system;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.TicketSales;
import com.ruoyi.system.service.ITicketSalesService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 售票管理Controller
 * 
 * @author ruoyi
 * @date 2024-06-28
 */
@RestController
@RequestMapping("/system/sales")
public class TicketSalesController extends BaseController
{
    @Autowired
    private ITicketSalesService ticketSalesService;

    /**
     * 查询售票管理列表
     */
    @PreAuthorize("@ss.hasPermi('system:sales:list')")
    @GetMapping("/list")
    public TableDataInfo list(TicketSales ticketSales)
    {
        startPage();
        List<TicketSales> list = ticketSalesService.selectTicketSalesList(ticketSales);
        return getDataTable(list);
    }

    /**
     * 导出售票管理列表
     */
    @PreAuthorize("@ss.hasPermi('system:sales:export')")
    @Log(title = "售票管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, TicketSales ticketSales)
    {
        List<TicketSales> list = ticketSalesService.selectTicketSalesList(ticketSales);
        ExcelUtil<TicketSales> util = new ExcelUtil<TicketSales>(TicketSales.class);
        util.exportExcel(response, list, "售票管理数据");
    }

    /**
     * 获取售票管理详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:sales:query')")
    @GetMapping(value = "/{orderId}")
    public AjaxResult getInfo(@PathVariable("orderId") Long orderId)
    {
        return success(ticketSalesService.selectTicketSalesByOrderId(orderId));
    }

    /**
     * 新增售票管理
     */
    @PreAuthorize("@ss.hasPermi('system:sales:add')")
    @Log(title = "售票管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TicketSales ticketSales)
    {
        return toAjax(ticketSalesService.insertTicketSales(ticketSales));
    }

    /**
     * 修改售票管理
     */
    @PreAuthorize("@ss.hasPermi('system:sales:edit')")
    @Log(title = "售票管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TicketSales ticketSales)
    {
        return toAjax(ticketSalesService.updateTicketSales(ticketSales));
    }

    /**
     * 删除售票管理
     */
    @PreAuthorize("@ss.hasPermi('system:sales:remove')")
    @Log(title = "售票管理", businessType = BusinessType.DELETE)
	@DeleteMapping("/{orderIds}")
    public AjaxResult remove(@PathVariable Long[] orderIds)
    {
        return toAjax(ticketSalesService.deleteTicketSalesByOrderIds(orderIds));
    }
}
